#include <libuv/uv.h>
#include <uvw/uvw.hpp>
#include <memory>
#include <sstream>
#include <thread>
#include <mutex>

#include "tcphandle.h"

namespace myrpc
{
	namespace mynet {

		class TcpServer
		{

		public:
			TcpServer();
			~TcpServer() = default;
			int Active(std::string ip , int port);
			void Active();
			void SetReach(std::function<void(PackagePtr)> f)
			{
				packgereachhandle_ = f;
			}
		private:	
			std::shared_ptr<TcpServer>  listener_;
			std::shared_ptr<uvw::Loop> loop_;
			std::function<void(PackagePtr)>  packgereachhandle_;
			std::vector<char> in_;
			std::vector<char> out_;
			std::vector<std::shared_ptr<TcpServer>> linklist_;
			std::vector<PackagePtr> packlist_;
			std::thread readthread;
			std::mutex readmtx;
		};

	}
}